package com.xuelang;

import com.alibaba.fastjson2.JSON;
import com.xuelang.pipeline.client.application.dto.ComponentDTO;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.pipeline.dto.PipelineDTO;
import com.xuelang.pipeline.entry.application.ComponentController;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertNotNull;


@Slf4j
@EnableCaching
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = SpringbootApp.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ComponentControllerTest {


    @Autowired
    private ComponentController componentController;


    @BeforeEach
    public void setUp() {
    }

    @Test
    public void testPagePipelineList() {
        PageRecord<PipelineDTO> pageRecord = new PageRecord<>();

        ApiResult<List<ComponentDTO>> result = componentController.listComponentByKeyword("");

        assertNotNull(result.getData());

        List<ComponentDTO> list = result.getData();

        log.info("list : {}", JSON.toJSONString(list));

        ApiResult<ComponentDTO> component = componentController.queryByid(String.valueOf(list.get(0).getId()));

        log.info("queryById dto : {}", JSON.toJSONString(component));

        assertNotNull(result.getData());
    }


}
